using TMPro;
using UnityEngine;
using UnityEngine.U2D;
using UnityEngine.UI;

public class ServerRightItem : MonoBehaviour
{
    public Button buttonSelf;
    public TextMeshProUGUI textSelf;
    public Image isNew;
    public Image state;
    //当前按钮的ID
    public int nowServerId;
    void Start()
    {
        buttonSelf.onClick.AddListener(() =>
        {
            //记录Id
            LoginManager.Instance.LoginData.serverId = nowServerId;
            //打开服务器面板
            UIManager.Instance.ShowPanel<ServerPanel>();
            //隐藏选服面板
            UIManager.Instance.HidePanel<ChooseServerPanel>();
        });
    }

    /// <summary>
    /// 用于初始化按钮显示相关
    /// </summary>
    /// <param name="serverInfo"></param>
    public void InitInfo(ServerInfo serverInfo)
    {

        //记录id
        nowServerId = serverInfo.id;
        //更新按钮的显示信息
        //文本
        textSelf.text = serverInfo.id + "区 " + serverInfo.name;
        //是否new
        isNew.gameObject.SetActive(serverInfo.isNew);
        //状态
        //加载图集文件
        SpriteAtlas sa = Resources.Load<SpriteAtlas>("Login");
        switch (serverInfo.state)
        {
            //无
            case 0:
                state.gameObject.SetActive(false);
                break;
            //流畅
            case 1:
                state.sprite = sa.GetSprite("ui_DL_liuchang_01");
                break;
            //繁忙
            case 2:
                state.sprite = sa.GetSprite("ui_DL_fanhua_01");
                break;
            //火爆
            case 3:
                state.sprite = sa.GetSprite("ui_DL_huobao_01");
                break;
            //维护
            case 4:
                state.sprite = sa.GetSprite("ui_DL_weihu_01");
                break;
        }

    }

}
